<template>
  <!-- 已发布的商品展示 -->
  <div class="feeds-container">
    <Waterfall :list="mineProductStore.soldList" imgSelector="image" :width="100" :animationEffect="'animate__zoomIn'"
      :breakpoints="breakpoints" :animationDelay="200" :animationDuration="1000" :posDuration="800"
      infinite-scroll-immediate="false" v-infinite-scroll="loadMore" infinite-scroll-delay="2000">
      <template #default="{ item, url }">
        <div class="waterfull-card">
          <!-- 封面 -->
          <LazyImg :url="Array.isArray(url) ? url[0] : url" style="border-radius: 10px;" />
          <div class="footer">
            <!-- 商品的标题 -->
            <div class="title"><span>{{ item.title }}</span></div>
            <!-- 价格 -->
            <div class="price">
              <span style="color: red;font-size: 16px;font-weight: 600;">￥{{ item.price }}</span>
              <span style="margin-left:5px;font-size: 12px;color: #666666;text-decoration: line-through">
                ￥{{ item.originalPrice }}
              </span>
              <el-tag type="success" size="small" v-if="item.status === 10"
                style="font-size: 12px;color: #67C23A;margin-left: 10px">交易中</el-tag>
              <el-tag type="danger" size="small" v-if="item.status === 12"
                style="font-size: 12px;color: #F56C6C;margin-left: 10px">已卖出</el-tag>
            </div>
            <!-- 展示状态 -->
            <div class="post" style="display:flex;justify-content: space-between;margin-bottom: 5px">
              <span style="font-size: 12px;color: #9e9e9e">发货方式：{{ item.postType === 0 ? '邮寄' : '自提' }}</span>
              <span style="font-size: 12px;color: #3a64ff;cursor: pointer">查看订单</span>
            </div>

          </div>
        </div>
      </template>
    </Waterfall>
  </div>
</template>

<script setup lang='ts'>
// import { ref, reactive } from 'vue'
import { Waterfall, LazyImg } from 'vue-waterfall-plugin-next'
import 'vue-waterfall-plugin-next/dist/style.css'
import { useMineProductStore } from '@/stores/modules/mineProduct'
import { onMounted, reactive } from 'vue'
const mineProductStore = useMineProductStore()

// 在 onMounted 中检查并加载数据
onMounted(() => {
  loadData()
})

// 加载数据
const loadData = async () => {
  mineProductStore.resetSold()
  await getMineSoldProductList()
}

// 加载更多
const loadMore = () => {
  getMineSoldProductList()
}

// 获取“我的”界面用户的商品列表
import useMineProduct from '@/hooks/useMineProduct'
const { getMineSoldProductList } = useMineProduct()

const breakpoints = reactive({
  1200: {
    // when wrapper width < 1200
    rowPerView: 5,
  },
  800: {
    // when wrapper width < 800
    rowPerView: 4,
  },
  500: {
    // when wrapper width < 500
    rowPerView: 2,
  },
})
</script>

<style lang='less' scoped>
.waterfull-card {
  transition: all .4s;

  &:hover {
    cursor: pointer;
    transform: translateY(-10px);
  }

  .footer {
    padding: 10px 0;

    .title {
      height: 24px;
      font-weight: 600;
      display: block;
      padding-left: 3px;
    }

    .price {
      height: 24px;
    }

    .post {
      height: 24px;
      padding-left: 3px;
    }

  }
}
</style>
